<?php
namespace Home\Controller;
use Think\Controller;
/**
 * 项目
 */
class HouseController extends Controller {
	public function first(){
		$wend = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));
		$sql = "select house.id,house.imgurl,house_num,start_time,end_time,`name`,state,concern_num,reduce,price from house LEFT JOIN sales on house.id=sales.house_id left join project on project.id=house.project_id where start_time<".$wend." ORDER BY `order` asc limit 0,4";
		$list = M()->query($sql);
		for($i=0;$i<count($list);$i++) {
			$list[$i]["week"] = 0;
			$list[$i]["imgurl"] = explode("|",$list[$i]["imgurl"]);
		}
		$data["tweek"] = $list;
		$sql = "select house.id,house.imgurl,house_num,start_time,end_time,`name`,state,concern_num,reduce,price from house LEFT JOIN sales on house.id=sales.house_id left join project on project.id=house.project_id where start_time>".$wend." ORDER BY `order` asc limit 0,4";
		$list = M()->query($sql);
		for($i=0;$i<count($list);$i++) {
			$list[$i]["week"] = 1;
			$list[$i]["imgurl"] = explode("|",$list[$i]["imgurl"]);
		}
		$data["nweek"] = $list;
		echo json_encode($data);
	}
	public function second(){
		$id = $_GET["id"];
		$project = M()->table("project")->join("left join project_img on project_img.project_id=project.id")->where("project_img.sort=1 and project.id=%d",array($id))->find();
		$project["array"] = M()->table("project_img")->field("imgurl")->where("sort>10 and project_id=%d",array($id))->select();
		$data["project"] = $project;
		$str = $_GET["room"]!=0?($_GET["room"]<3?" and house.room=".$_GET["room"]:" and house.room>2"):"";
		$list = M()->table("house")->join("left join sales on house.id=sales.house_id")->where("house.project_id=".$id.$str);
		if($_GET["sort"] == "price"){
			$list = $list->order("price asc");
		}elseif($_GET["sort"] == "discount"){
			$list = $list->order("discount desc");
		}else{
			$list = $list->order("concern_num desc");
		}
		$list = $list->select();
		for($i=0;$i<count($list);$i++) {
			$list[$i]["imgurl1"] = explode("|",$list[$i]["imgurl1"]);
		}
		$data["list"] = $list;
		echo json_encode($data);
	}
	public function third(){
		$id = $_GET["id"];
		$info = M("house")->field("house.imgurl2,name,house_type,face,room,living,toilet,square,house.introduction")->join("left join project on house.project_id=project.id")->where("house.id=%d",array($id))->find();
		$info["imgurl2"] = explode("|",$info["imgurl2"]);
		echo json_encode($info);
	}
}
?>